package com.ymatou.iapi.sellercs.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellercs.parameter.GetDiscourseListByCSIdBean;
import com.ymatou.iapi.sellercs.service.GetDiscourseListByCSIdCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.SellerCSIMCallService;
import com.ymttest.database.sqlwapper.YmtSellerCSIMWapper;
import com.ymttest.utils.EnvSetup;
/**
*下线不活跃的客服
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetDiscourseListByCSId{
	private static GetDiscourseListByCSIdBean getdiscourselistbycsidBean;
	private static GetDiscourseListByCSIdCall getdiscourselistbycsidCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static YmtSellerCSIMWapper YmtSellerCSIMWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("下线不活跃的客服");
	}

	@Before
	public void caseUp() {
		getdiscourselistbycsidBean=new GetDiscourseListByCSIdBean();
		getdiscourselistbycsidCall=new GetDiscourseListByCSIdCall();
		YmtSellerCSIMWapper=new YmtSellerCSIMWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getdiscourselistbycsidCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetDiscourseListByCSId_001() {
		Logger.start(true,"获取子客服话术列表成功");
		try {
			SellerCSIMCallService.DelAllDiscourse(sellerId);
			SellerCSIMCallService.AddDiscourse(sellerId, "话术", "具体内容");
			
			Map<String ,Map> dbmap=new HashMap<String ,Map>();
			YmtSellerCSIMWapper.selectIndividualdiscourseByCsid(sellerId).stream().forEach(m->{dbmap.put(m.get("id").toString(), m);});
			
			getdiscourselistbycsidBean.setCSId(sellerId);
			getdiscourselistbycsidCall.setData(getdiscourselistbycsidBean);
			getdiscourselistbycsidCall.callService();			
			Logger.verifyIsContains("200", getdiscourselistbycsidCall.getString("Status"), "验证Status");	
			Logger.debug(FormatUtil.beanToGSONString(getdiscourselistbycsidCall.getResult()));
			getdiscourselistbycsidCall.getResult().forEach(result->{
				result.getList().forEach(dis->{
					// [{CategoryId=3abd471faa634c1bab70698e9eb0d24d, icTitle=话术类别d3863, CSId=24635724, cTitle=null, id=null, cSort=null, icSort=1}]
					Map db=dbmap.get(dis.getId());
					Logger.verifyEquals(db.get("CategoryId"), dis.getCategoryId(), "验证CategoryId");
					Logger.verifyEquals(db.get("cSort"), dis.getSort(), "验证cSort");
					Logger.verifyEquals(db.get("cTitle"), dis.getTitle(), "验证cTitle");
					Logger.verifyEquals(db.get("icSort"), result.getSort(), "验证icSort");
					Logger.verifyEquals(db.get("icTitle"), result.getTitle(), "验证icTitle");
				});
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetDiscourseListByCSId_002() {
		Logger.start(true,"不输入csid失败");
		try {
			getdiscourselistbycsidCall.setData(getdiscourselistbycsidBean);
			getdiscourselistbycsidCall.callService();			
			Logger.verifyIsContains("400", getdiscourselistbycsidCall.getString("Status"), "验证Status");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}